﻿using System;
using System.Web;
namespace DataAccess 
{ 
    public class Link 
    { 
        private static string BuildAbsolute(string relativeUrl) 
        { 
            Uri uri = HttpContext.Current.Request.Url;
            string app = HttpContext.Current.Request.ApplicationPath; 
            if (!app.EndsWith("/")) app += "/";
            relativeUrl = relativeUrl.TrimStart('/'); 
            return HttpUtility.UrlPathEncode(String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUrl)); 
        } 

        public static string ToCategory(string categoryId, string page)
        { 
            if (page == "1") 
                return BuildAbsolute(String.Format("Catalog.aspx?MaThuongHieu={0}", categoryId)); 
            else 
                return BuildAbsolute(String.Format("Catalog.aspx?CategoryID={0}&Page={1}", categoryId, page)); 
        } 

        public static string ToCategory(string categoryId)
        {
            return ToCategory(categoryId, "1");
        }

        public static string ToCatalog(string page)
        {
            if (page == "1")
                return BuildAbsolute("Catalog.aspx");
            else
                return BuildAbsolute(String.Format("Catalog.aspx?Page={0}", page));
        }

        public static string ToCatalog()
        {
            return ToCatalog("1");
        }

        public static string ToProduct(string productId)
        {
            return BuildAbsolute(String.Format("Product.aspx?ProductID={0}", productId));
        }

        public static string ToAddToCart(string productId)
        {
            return BuildAbsolute(String.Format("AddToCart.aspx?ProductID={0}", productId));
        }

        public static string ToProductImage(string fileName)
        {
            return BuildAbsolute(String.Format("ProductImages/{0}", fileName));
        }
              
        public static string ToSearch(string searchString, int giaDuoi, int giaTren, string page)
        {
            string gd = "", gt = "";
            if (giaDuoi != -1)
                gd = giaDuoi.ToString();
            if (giaTren != 12345)
                gt = giaTren.ToString();
            if (page == "1") 
                return BuildAbsolute(String.Format("Search.aspx?Search={0}&Price={1}&to={2}", searchString, gd, gt));
            return BuildAbsolute(String.Format("Search.aspx?Search={0}&Price={1}&to={2}&Page={3}", searchString, gd, gt, page));
        } 
        
        public static string ToSearch(string searchString, int giaDuoi, int giaTren) 
        { return ToSearch(searchString, giaDuoi, giaTren, "1"); }
        public static string ToAdminProduct(string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Admin/Product.aspx"));
            return BuildAbsolute(String.Format("Admin/Product.aspx?Page={0}", page));
        }
        public static string ToAdminProduct()
        {
            return ToAdminProduct("1");
        }
        public static string ToAdminUpload(string clientId, string page)
        {
            if (page == "1")
                return BuildAbsolute(
                String.Format("Admin/Upload.aspx?id={0}", clientId));
            return BuildAbsolute(
            String.Format("Admin/Upload.aspx?id={0}&Page={1}", clientId, page));
        }
        public static string ToAdminUpload(string clientId)
        {
            return ToAdminUpload(clientId, "1");
        }
    } 
}